// Provides plugin.dll for Photoshop plugins.
#include <windows.h>
#include "..\photoshop.h"

#define export __declspec (dllexport) __cdecl

void print (const char *text)
{
	HANDLE handle = GetStdHandle (STD_OUTPUT_HANDLE);
	
	if (handle)
	{
		DWORD written;
		int length;
		
		for (length = 0; text [length]; length ++);
		WriteFile (handle, text, length, &written, 0);
	}
}

int _acrtused_dll;

BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID reserved)
{
	return TRUE;
}

void export SetFPos ()
{
	print ("SetFPos\n");
}

void export GetEOF ()
{
	print ("GetEOF\n");
}

void export FSRead ()
{
	print ("FSRead\n");
}

void export FSWrite ()
{
	print ("FSWrite\n");
}

void export DisposePtr ()
{
	print ("DisposePtr\n");
}

void export NewPtr ()
{
	print ("NewPtr\n");
}

void export NewPtrClear ()
{
	print ("NewPtrClear\n");
}

void export UtilWriteDescriptors ()
{
	print ("UtilWriteDescriptors\n");
}

void export UtilReadDescriptors ()
{
	print ("UtilReadDescriptors\n");
}

void export HLock ()
{
	print ("HLock\n");
}

void export HUnlock ()
{
	print ("HUnlock\n");
}

void export CenterWindow ()
{
	print ("CenterWindow\n");
}

void export BlockMoveData ()
{
	print ("BlockMoveData\n");
}

// Returns 0 on success, non-zero on failure.
int export InitializePIExpressDialogs (PhotoshopAboutRecord *record)
{
	print ("InitializePIExpressDialogs\n");
	return 0;
}

void export DeinitializePIExpressDialogs ()
{
	print ("DeinitializePIExpressDialogs\n");
}

#define IS_INTRESOURCE(VALUE) ((uintptr_t) (VALUE) < 65536)
#define LONG_PTR uintptr_t

BOOL CALLBACK each (HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG_PTR lParam)
{
	print ("Resource: ");
	if (IS_INTRESOURCE (lpszType))
		print ("(int)");
	else
		print (lpszType);
	print (" ");
	if (IS_INTRESOURCE (lpszName))
		print ("(int)");
	else
		print (lpszName);
	print ("\n");
	return 1;
}

typedef intptr_t INT_PTR;

INT_PTR CALLBACK DialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return 0;
}

HWND export PIDMWinExpressDialog (LPCSTR resource, HANDLE instance)
{
	print ("PIDMWinExpressDialog\n");
	HWND result = CreateDialogA (instance, resource, 0, (DLGPROC) &DialogProc);
	if (result) print ("Created!\n");
	return result;
	/*for (int type = 0; type < 16; type ++)
	{
		int result = EnumResourceNamesA (instance, (char *) type, (ENUMRESNAMEPROC) &each, 0);
		if (!result)
		{
			int error = GetLastError ();
			if (error != NO_ERROR && error != ERROR_RESOURCE_TYPE_NOT_FOUND)
				print ("Oh no something happened\n");
		}
	}
	print ("Post\n");*/
	return 0;
}
